package com.hlcl.huaji.view;

import android.os.Bundle;
import android.view.View;

import com.elcl.activity.BaseActivity;
import com.elcl.network.AppContext;
import com.elcl.util.StringUtils;
import com.elcl.util.viewutils.ViewUtils;
import com.elcl.util.viewutils.WindowUtils;
import com.elcl.widget.comp.toast.ToastUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hlcl.huaji.R;
import com.hlcl.huaji.model.LoginResponse;
import com.hlcl.huaji.model.LoginResult;
import com.hlcl.huaji.server.NetCode;
import com.hlcl.huaji.server.OrderServer;

/**
 * Created by lichunlin on 2018/6/17.
 * 提现  绑定客户的界面
 */

public class WithDrawAccountActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_account_modify);

        WindowUtils windowUtils = new WindowUtils();
        windowUtils.fullScreen(WithDrawAccountActivity.this);
        getUserInfo();
        initView();
    }

    private LoginResponse loginResponse;
    private LoginResult loginResult;

    private void getUserInfo() {
        String userInfo = AppContext.getUerInfo();
        if (StringUtils.isNotBlank(userInfo)) {
            loginResult = gson.fromJson(userInfo, new TypeToken<LoginResult>() {
            }.getType());
            if (null != loginResult) {
                loginResponse = loginResult.getjData();
                if (null != loginResponse) {
                    setText(R.id.edt_name, loginResponse.getCardUserName());
                    setText(R.id.edt_type, loginResponse.getCardName());
                    setText(R.id.edt_account, loginResponse.getCardNo());
                }
            }
        }
    }

    private String[] prompts = new String[]{"请输入收款方", "请输入收款方式", "请输入收款账号"};
    private String[] content;

    private void initView() {
        setListener(R.id.tv_save, new View.OnClickListener() {//保存地址
            @Override
            public void onClick(View v) {
                content = ViewUtils.isEdtNull(WithDrawAccountActivity.this, prompts, R.id.edt_name, R.id.edt_type, R.id.edt_account);
                OrderServer.getInstance().modifyCardNo(netHandler, content[0], content[1], content[2]);
            }
        });
    }

    private Gson gson = new Gson();

    @Override
    protected void praseJson(int reqId, String json) {
        if (reqId == NetCode.ID_MODIFYCARD_NO) {//修改地址
            ToastUtils.showToast("修改账户成功");
            loginResponse.setCardUserName(content[0]);
            loginResponse.setCardName(content[1]);
            loginResponse.setCardNo(content[2]);
            loginResult.setjData(loginResponse);
            AppContext.setUserInfo(gson.toJson(loginResult));
            setResult(RESULT_OK);
            finish();
        }


    }
}
